$(function(){
	tmOption.load(null);
	tmOption["top"]();
});
var tmOption = {
	pageNo:0,
	pageSize:10,
	mark:true,
	timer:null,
	/********加载和初始化页码*********/
	loadData:function(obj){
		this.load(obj);
		tmOption.pageNo++;
	},
	/********加载查询博客信息*********/
	load:function(obj){
		clearTimeout(tmOption.timer);
		tmOption.timer = setTimeout(function(){//异步处理中--节流
			if(!tmOption.mark)return;
			var pno = tmOption.pageNo * tmOption.pageSize;
			var psize = tmOption.pageSize;
			var params = {pageNo:pno,pageSize:psize};
			$.ajax({
				type:"post",
				url:basePath+"/blog/loadData.do",
				data:params,
				success:function(data){
					if(data&&data.length>0){
						var html = "";
						for(var i = 0;i<data.length;i++){
							var blog = data[i];
							var desc = blog.description;
 							if(desc.length>120)
 								desc = desc.substring(0,120)+"...";
							html+="<li class='items'>"+
								"	<a href='"+basePath+"/blog/detail/"+blog.id+".do' class='imgbox pr'>"+
								"	<img class='lazy' alt='#' src='"+basePath+"/"+blog.img+"' style='display: inline;' />"+
								"	<div class='iover'></div>"+
								"	</a>"+
								"	<div class='slbox'>"+
								"	<h3 class='title'><a href='"+basePath+"/blog/detail/"+blog.id+".do'>"+blog.title+"</a></h3>"+
								"	<p class='info'>"+
								"	<span>"+blog.createTime+"<i class='iconfont'></i></span>"+
								"	<span>"+blog.comments+"<i class='iconfont icon-dianping'></i></span>"+
								"	<span>"+blog.hits+"<i class='iconfont icon-hit'></i></span>"+
								"	</p>"+
								"	<p class='desc'>"+desc+"<a class='read' href='"+basePath+"/blog/detail/"+blog.id+".do'>阅读全文</a></p>"+
								"	</div>"+
								"	</li>";
						}
						$("#databox").append(html);
//						document.body.scrollTop = document.body.scrollHeight;
					}else{
						tmOption.mark = false;
							$(obj).removeAttr("onclick").find(".text").html("数据加载完毕...");
	 					}
					}
				});
			
		},1000);
		
	},
	top:function(){
		$.ajax({
			type:"post",
			url:basePath+"/blog/loadTop.do",
			data:{pageSize:3},
			success:function(data){
				if(data){
					var html = "";
					data.forEach(function(obj,index){
						if(index==0){
							html+="<div class='bg_pic pr'>"+
							"	<div class='iover'></div>"+
							"	<div class='imgi'><img src='"+basePath+"/"+obj.img+"' title='"+obj.title+"'/></div>"+
							"	<a href='"+basePath+"/blog/detail/"+obj.id+".do' title='"+obj.title+"' class='btext'>"+
							"	<h1 class='cp_h1'>"+obj.title+"</h1>"+
							"	</a>"+
							"	</div>";
						}else{
							html+="<div class='small_pic pr'>"+
							"	<div class='iover'></div>"+
							"	<div><img src='"+basePath+"/"+obj.img+"' title='"+obj.title+"'/></div>"+
							"	<a href='"+basePath+"/blog/detail/"+obj.id+".do' title='"+obj.title+"'  class='btext2'>"+obj.title+"</a>"+
							"	</div>";
							
						}
					});
					$(".cheader").html(html);
				}
			}
		});
	},
		
	save:function(){
		
	},
	
	update:function(){
		
	},
	
	del:function(){
		
	},
	
	search:function(){
		
	}
};